package com.yeeyk.shell.controller;


import com.yeeyk.shell.common.Constants;
import com.yeeyk.shell.common.ExcelParser;
import com.yeeyk.shell.entity.RawXlsRom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Set;

/**
 * Created by zhangjuntao on 2017/3/24.
 */
public class ShellController {
    private  static final Logger LOGGER = LoggerFactory.getLogger(ShellController.class);

    @PostMapping("/readExcel")
    public String readExcel(@RequestParam(value = "file") MultipartFile file, HttpServletRequest req, HttpServletResponse resp){
        try {
            if ( Constants.CAN_UPDATE_SHELL.equals(Boolean.FALSE) )
                return "";
            Constants.CAN_UPDATE_SHELL.set(Boolean.FALSE);
            Set<RawXlsRom> ramXmlRomSet = Constants.RAW_EXCEL_SET ;
            List<String[]> excels = ExcelParser.readExcel(file);
            for( String[] row:excels ){
                System.out.println(row.toString());
            }
        } catch (Exception e) {
            LOGGER.info("读取excel文件失败", e);
        }finally {
            return " ";
        }
    }



}
